<template>
  <j-modal
    :title="$t('popup.selectDeliveryOrder')"
    :width="width"
    :visible="priceVisible"
    @cancel="priceHandleCancel"
    style="overflow-y: hidden">
    <template slot="footer">
      <a-button @click="priceHandleCancel">{{$t('inPrint.cancel')}}</a-button>
      <a-button type="primary" @click="priceHandleOk">{{$t('popup.determine')}}</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <div>
          <a-table
            ref="table"
            size="middle"
            :customRow="rowClick"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :row-selection="{
              selectedRowKeys: selectedRowKeys2,
              onChange: onSelectChange2,
              onSelect: onSelect2,
              onSelectAll: onSelectAll2,
              type:'radio'
            }"
            @change="handleTableChange">
          </a-table>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns1"
            :dataSource="dataSource1"
            :scroll="scroll"
            :loading="loading"
            :row-selection="{
              selectedRowKeys: selectedRowKeys1,
              onChange: onSelectChange1,
              onSelect: onSelect1,
              onSelectAll: onSelectAll1,
            }"
           >
          </a-table>
        </div>
    </a-spin>
  </j-modal>
</template>
<script>
  import pick from 'lodash.pick'
  // import ManyAccountModal from '../dialog/ManyAccountModal'
  // import CustomerModal from '../../system/modules/CustomerModal'
  // import AccountModal from '../../system/modules/AccountModal'
  // import HistoryBillList from '../dialog/HistoryBillList'
  // import { FormTypes } from '@/utils/JEditableTableUtil'
  // import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  // import { BillModalMixin } from '../mixins/BillModalMixin'
  // import { getMpListShort,handleIntroJs } from "@/utils/util"
  import { BillListMixin } from '../mixins/BillListMixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { deleteAction, getAction, postAction, downFile, getFileAccessHttpUrl } from '@/api/manage'
  // import JSelectMultiple from '@/components/jeecg/JSelectMultiple'
  // import JUpload from '@/components/jeecg/JUpload'
  // import JDate from '@/components/jeecg/JDate'
import { getLanCode } from '@/lang'
  import Vue from 'vue'
  export default {
    name: "SingleSourceModal",
    mixins:[JeecgListMixin,BillListMixin],
    props: {
      visible: {
        type: String | Boolean ,
        required: true
      },
    },
    watch:{
      visible(val, valOld) {
        this.priceVisible = val
      }
    },
    // mixins: [JEditableTableMixin, BillModalMixin, BillListMixin],
    components: {
      // ManyAccountModal,
      // CustomerModal,
      // AccountModal,
      // HistoryBillList,
      // JUpload,
      // JDate,
      // JSelectMultiple,
      // VNodes: {
      //   functional: true,
      //   render: (h, ctx) => ctx.props.vnodes,
      // }
    },
    data () {
      return {
        title:this.$t('setailManagement.operation'),
        width: '1550px',
        form: this.$form.createForm(this),
        // 查询条件
        queryParam: {
          number: "",
          materialParam: "",
          type: "出库",
          subType: "配送",
          roleType: Vue.ls.get('roleType'),
          depotId: "",
          creator: "",
          status: "1,3",
          remark: ""
        },
        dataSource1: [],
        moreStatus: false,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        priceVisible: this.visible,
        // visible: false,
        operTimeStr: '',
        prefixNo: 'PSD',
        fileList:[],
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        refKeys: ['materialDataTable', 'customerDataTable', 'warehouseDataTable'],
        activeKey: 'materialDataTable',
        confirmLoading: false,
        validatorRules:{
          valenceSpecies:{
            rules: [
              { required: true, message: this.$t('popup.pleaseEnterPriceCategory')+'!' }
            ]
          },
          algorithm:{
            rules: [
              { required: true, message: this.$t('popup.pleaseSelectAdditionSubtraction')+'!' }
            ]
          },
          warehouse:{
            rules: [
              { required: true, message: this.$t('setailManagement.warehouse')+'!' }
            ]
          }
        },
        // 表头
        columns: [
          { title: this.$t('manuManagement.documentNo'), dataIndex: 'number',width:160,
            customRender: (text,record,index)=>{
              if(record.linkNumber) {
                return text + `[${this.$t('otherJS.returnStr')}]`;
              } else {
                return text;
              }
            }
          },
          { title: this.$t('manuManagement.productInformation'), dataIndex: 'materialsList',width:220, ellipsis:true,
            customRender:function (text,record,index) {
              if(text) {
                return text.replace(",","，");
              }
            }
          },
          { title: this.$t('popup.purchasingWarehouse'), dataIndex: 'depotName',width:145},
          { title: this.$t('popup.distributionWarehouse'), dataIndex: 'anotherDepotName',width:145},
          { title: this.$t('setailManagement.documentDate'), dataIndex: 'operTimeStr',width:145},
          { title: this.$t('popup.handler'), dataIndex: 'loginName',width:80, ellipsis:true},
          { title: this.$t('setailManagement.totalAmount'), dataIndex: 'totalPrice',width:80},
          { title: this.$t('setailManagement.state'), dataIndex: 'status', width: 80, align: "center",
            scopedSlots: { customRender: 'customRenderStatus' }
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center", width: 150,
          //   scopedSlots: { customRender: 'action' },
          // }
        ],
        // 表头
        columns1: [
          // { title: '单据编号', dataIndex: 'number',width:160,
          //   customRender:function (text,record,index) {
          //     if(record.linkNumber) {
          //       return text + `[${this.$t('otherJS.returnStr')}]`;
          //     } else {
          //       return text;
          //     }
          //   }
          // },
          { title: this.$t('otherJS.productName'), dataIndex: 'name',width:145 },
          { title: this.$t('reportQuery.unit'), dataIndex: 'unit',width:145 },
          { title: this.$t('manuManagement.received'), dataIndex: 'finishNumber',width:80 },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'basicNumber',width:80 },
          { title: this.$t('reportQuery.unitPrice'), dataIndex: 'unitPrice',width:80 },
          { title: this.$t('reportQuery.amount'), dataIndex: 'allPrice',width:80 },
          { title: this.$t('otherJS.promotion'), dataIndex: 'priceNote', width: 80 },
          // { title: '折扣', dataIndex: 'totalPrice',width:80 },
          // { title: '折扣单价', dataIndex: 'status', width: 80 },
          // { title: '折后金额', dataIndex: 'status', width: 80 },
        ],
        url: {
          list: "/depotHead/list",
          add: '/depotHead/addDepotHeadAndDetail',
          edit: '/depotHead/updateDepotHeadAndDetail',
          detailList: '/depotItem/getDetailList'
        }
      }
    },
    // created () {
      
    // },
    methods: {
      priceHandleCancel() {
        this.priceVisible = false
        this.dataSource = []
        this.dataSource1 = []
        this.$emit('visibleType', this.priceVisible);
      },
      priceHandleOk() {
        let item = this.dataSource.find(v=>v.id === this.selectedRowKeys2[0]) || {}
        if(!this.selectionRows2.length){
          this.$message.error(this.$t('popup.pleaseSelectMaterial'))
          return;
        }
        
        this.$emit('priceList', this.selectionRows2,item.number);
        this.priceHandleCancel()
        // this.form.validateFields((err, values) => {
        //   // 这里做逻辑处理
        //   console.log(values) // { username: '' }
        // })
      },
      rowClick(record, index) {
        return {
          on: {
            click: () => {
              console.log(record)
              let param = {
                headerId: record.id,
                mpList: '',
                linkType: 'basic'
              }
              getAction(this.url.detailList, param).then((res) => {
                  if (res && res.code === 200) {
                    let dataSource1 = res.data.rows
                    this.dataSource1 = dataSource1.filter(v=>v.finishNumber < v.basicNumber)
                  }
              })
            },
            dblclick: () => {
              console.log('双击了我')
            },
          }
        }
      },
      priceFormula() {

      },
      //调用完edit()方法之后会自动调用此方法
      editAfter() {
        // this.billStatus = '0'
        // this.changeColumnHide()
        // if (this.action === 'add') {
        //   this.addInit(this.prefixNo)
        //   this.personList.value = ''
        //   this.fileList = []
        //   this.$nextTick(() => {
        //     handleIntroJs(this.prefixNo, 1)
        //   })
        // } else {
        //   this.model.operTime = this.model.operTimeStr
        //   if(this.model.accountId == null) {
        //     this.model.accountId = 0
        //     this.manyAccountBtnStatus = true
        //     this.accountIdList = this.model.accountIdList
        //     this.accountMoneyList = this.model.accountMoneyList
        //   } else {
        //     this.manyAccountBtnStatus = false
        //   }
        //   this.personList.value = this.model.salesMan
        //   
        // this.form.resetFields();
          // this.$nextTick(() => {
          //   this.form.setFieldsValue(pick(this.model,'priceDiscount','algorithm','valenceSpecies'))
            // this.form.setFieldsValue({
            //   algorithm: '*',
            //   valenceSpecies: '零售价',
            //   priceDiscount: '0.2',
            // })
          // });
          // getMaterialByBarCode(param).then((res) => {
          //         if (res && res.code === 200) {
          //         }
          //     })
          
          this.queryParam.beginTime = ''
          this.queryParam.endTime = ''
          this.queryParam.depotStatus = '1'
          this.loadData()
          // this.getDepotData()
          // this.initUser()
        //   // 加载子表数据
        //   let params = {
        //     headerId: this.model.id,
        //     mpList: getMpListShort(Vue.ls.get('materialPropertyList'))  //扩展属性
        //   }
        //   let url = this.readOnly ? this.url.detailList : this.url.detailList;
        //   this.requestSubTableData(url, params, this.materialTable);
        // }
        // //复制新增单据-初始化单号和日期
        // if(this.action === 'copyAdd') {
        //   this.model.id = ''
        //   this.model.tenantId = ''
        //   this.copyAddInit(this.prefixNo)
        // }
        // this.initCustomer()
        // this.initSalesman()
        // this.initAccount()
      },
      //提交单据时整理成formData
      // classifyIntoFormData(allValues) {
      //   let totalPrice = 0
      //   let billMain = Object.assign(this.model, allValues.formValue)
      //   let detailArr = allValues.tablesValue[0].values
      //   billMain.type = '其它'
      //   billMain.subType = '促销特价订单'
      //   billMain.defaultNumber = billMain.number
      //   for(let item of detailArr){
      //     item.depotId = '' //订单不需要仓库
      //     totalPrice += item.allPrice-0
      //   }
      //   billMain.totalPrice = totalPrice
      //   if(billMain.accountId === 0) {
      //     billMain.accountId = ''
      //   }
      //   billMain.accountIdList = this.accountIdList.length>0 ? JSON.stringify(this.accountIdList) : ""
      //   billMain.accountMoneyList = this.accountMoneyList.length>0 ? JSON.stringify(this.accountMoneyList) : ""
      //   if(this.fileList && this.fileList.length > 0) {
      //     billMain.fileName = this.fileList
      //   } else {
      //     billMain.fileName = ''
      //   }
      //   if(this.model.id){
      //     billMain.id = this.model.id
      //   }
      //   billMain.salesMan = this.personList.value
      //   billMain.status = this.billStatus
      //   return {
      //     info: JSON.stringify(billMain),
      //     rows: JSON.stringify(detailArr),
      //   }
      // },
      // handleHistoryBillList() {
      //   let organId = this.form.getFieldValue('organId')
      //   this.$refs.historyBillListModalForm.show('其它', '销售订单', '客户', organId);
      //   this.$refs.historyBillListModalForm.disableSubmit = false;
      // },
    }
  }
</script>
<style scoped>

</style>